Skip to content

Landscape and wildlife: 17 functions, 10 at 100% - #526

Draft
gynt wants to merge 46 commits into
mainfrom
reimpl/landscape-wildlife-development
Draft

gynt wants to merge 46 commits into
mainfrom
reimpl/landscape-wildlife-development

Conversation

@gynt

@gynt gynt commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

11 landscape and wildlife functions, plus 6 callees reimplemented here so the /GL (LTCG) build keeps this in ecx across the calls as the original does. The functions were ported from gynt's catch-all branches: this branch is origin/main plus the copied files, compile fixes, matching work and status.

Measured with reccmp, with both the struct and the function resolvers enabled and main's /GL callees on.

10 of 17 functions at 100%. The others hit a wall: the blocker named for each was measured, and the source forms tried against it tied or scored worse.

At 100%

Function Address Ported at
LandscapeState::createRock 0x004F2140 64.1%
LandscapeState::updateTreeStage 0x004F3960 54.1%
WildlifeState::renderDebugDataMapData 0x0052BF40 16.0%
WildlifeState::floodFillField13FromCell 0x0052C570 new
WildlifeState::floodFillField20FromCell 0x0052C810 new
WildlifeState::hasAdjacentCellWithField24Or25 0x0052D620 new
WildlifeState::isAttackStagingCandidateCell 0x0052D690 new
WildlifeState::floodFillZoneProximityFromCell 0x0052D720 new
WildlifeState::floodFillCasDisFromSignpost 0x0052D9D0 new
WildlifeState::updateWildlife 0x0052DF30 28.9%

Hit a wall

Function Address Match Ported at Why it stops there
LandscapeState::spawnCrowFromNearbyTree 0x004F3150 98.3% 23.4% Register allocation of two loads.
WildlifeState::updateSection1034Info 0x0052E020 94.0% 67.4% The outer 20-pass loop counts down in ours and up in a stack slot in the original. do/while, while, !=, pre-declared and unsigned counters all still count down under /GL.
LandscapeState::createTree 0x004F1CE0 89.6% 56.6% Register allocation of the tile arithmetic and the parameter loads.
WildlifeState::updateNofFpoints 0x0052E120 79.0% 8.8% The binary-map base is folded into the y * 400 induction variable; register naming.
WildlifeState::findAndSetNewRallyPointForDeerAndLions 0x0052CAB0 77.0% 44.7% Stack-slot and register allocation in the search loops.
WildlifeState::updateWildlifeGrid 0x0052BA10 74.2% 57.3% MSVC strength-reduces tileY * 400 and the *12 row offsets into three stack slots (frame 0x368 vs 0x35c); the original recomputes them per tile. Every loop shape (tileY in outer/inner scope, int/uint) gives identical code.
WildlifeState::buildRallyPointPathForTribe 0x0052CFE0 70.6% 42.2% Stack-slot and register allocation in the walk.

Behaviour fixes

These were wrong in the decompiler output and are fixed against the binary:

  • renderDebugDataMapData never returned: the copied row loop ended with if (40 < i) {} inside while (true).
  • createTree free-slot search stepped 78 trees at a time (Ghidra pointer stride in the wrong unit) and gave up one slot late.
  • createRock slot search wrote past the array when the table was full (3999 < instead of >= 3999).
  • updateTreeStage: a tree reaching stage 6 now dies and returns, and a spread past the interval resets to stage 5 and returns, instead of running the spread/re-seed code.
  • findAndSetNewRallyPointForDeerAndLions wrote one past each 1600-entry coordinate array (wrap at 1600 < instead of >= 1600).
  • updateSection1034Info: out-of-bounds write from a pointer stride in the wrong unit.
  • types commit: AttackInfo::nof_fpointsArray holds 100 entries, not 50.

Type and header changes are in their own types: commits. Resolver flags are not committed.


🤖 Generated with Claude Code

https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ

gynt and others added 30 commits November 28, 2026 13:56
…wildlife-development

Their best match lives only on gynt's catch-all branches, which are ~2080 cpp
files ahead of their merge base and 412 commits behind main. The cpp files are
copied unchanged, without the headers of those branches:
- gynt/reimpl/UI-DisplayElements-pr-development@fbc092e15 (11)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Renamed fields, globals and resolvers by address, enum-typed arguments,
array fields indexed directly, clang-format.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
SHC_3BB0A8C1_0x004F1CE0 56.6% createTree
SHC_3BB0A8C1_0x004F2140 64.1% createRock
SHC_3BB0A8C1_0x004F3150 23.4% spawnCrowFromNearbyTree
SHC_3BB0A8C1_0x004F3960 54.1% updateTreeStage
SHC_3BB0A8C1_0x0052BA10 57.3% updateWildlifeGrid
SHC_3BB0A8C1_0x0052BF40 16.0% renderDebugDataMapData
SHC_3BB0A8C1_0x0052CAB0 44.7% findAndSetNewRallyPointForDeerAndLions
SHC_3BB0A8C1_0x0052CFE0 42.2% buildRallyPointPathForTribe
SHC_3BB0A8C1_0x0052DF30 28.9% updateWildlife
SHC_3BB0A8C1_0x0052E020 67.4% updateSection1034Info
SHC_3BB0A8C1_0x0052E120 8.8% updateNofFpoints

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
- updateNofFpoints 8.8 -> 61.0: one 40x40 grid scan (x, y = 10 * cell + 5)
  instead of Ghidra's five specialised unrolled copies; MSVC unrolls the
  plain loop 5x like the original and strength-reduces `y <= 399` to the
  same `y * 12 <= 0x12b4` test. The path area is read as a signed short and
  the bubble sort is a for loop inside do/while(swapped). Left: register
  allocation for the column and row counters.
- updateWildlife 28.9 -> 50.3: both passes are plain 40x40 loops and the
  flood-fill choice is an else-if chain. Left: the original keeps `this`
  in ecx across the flood-fill calls (LTCG) where we spill it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Both fix behaviour carried over from the decompiler output:

- updateTreeStage 54.1 -> 85.7: a tree reaching stage 6 dies and returns
  (Ghidra also ran the spread code for it), and a spread past the interval
  resets the tree to stage 5 and returns instead of falling through to
  re-seed at stage 3. getValueFrom0UpTo3ForTreeTypeAndTreeStage and
  createTree are called on the global DAT_LandscapeState like the original,
  and the one big condition is split into early returns. Left: edx kept
  across the size call (LTCG).
- createRock (64.1, unchanged): the slot search gives up at rockID >= 3999
  like the original; with Ghidra's `3999 <` test a full table fell out of
  the loop at 4000 and wrote past the array. Left: which register holds 1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
23.4 -> 98.3. Ghidra's four unrolled copies of the keep search are one
`for` over players 1..8, which MSVC unrolls 4x itself. The distance is
max(|dx|, |dy|) written as a ternary over abs(); the if-form costs half
the match. The "sound played" flag is a BOOL (the original stores a
dword). Left: two register choices for the tree-layer index and the owner.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
16.0 -> 48.9 (normalized 55.4). Fixes a hang: the copied body ended its
row loop with `if (40 < iVar8) {}` inside `while (true)`, so the debug map
never returned. It is now two plain 40x40 loops like the original.

Rebuilt from the binary rather than Ghidra's goto web:
- each display type calls renderTextToScreen in its own arm, as the
  original pushes the full argument list per arm
- each display type is an if/else-if chain that picks one ushort colour;
  the original tail-merges the shared endings (type 5 into type 4, type 7
  into type 6)
- the grid lines are two plain 41-step loops

Left: register allocation. The original keeps y in ebp and x + 2 in ebx for
the whole function, where we reload y from the stack.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
42.2 -> 69.4. Both direction scans are one `for` over the eight
clockwise offsets instead of Ghidra's four unrolled, specialised copies.
MSVC unrolls them 4x itself. The walk starts at a random direction and
wraps with `if (direction >= 8)`, matching the original's `cmp 8; jl`.

What reccmp rewarded, though quick_diff ranked it lower:
- the grid bounds as `<= 39`, which the original tests with `cmp 0x27; ja`
- the candidate x read before y, and the neighbour x computed before y
- the unit index read inline from the tribe
- the chosen cell cleared before param_2 takes its distance

Left: the original keeps the best direction and the walk position in
other stack slots and registers.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
44.7 -> 71.5. Built the same way as buildRallyPointPathForTribe: plain
direction loops instead of Ghidra's specialised copies, the walk wrapping
with `direction >= 8`, and the bound literals the original compares
against (`<= 39`, `<= 399`, `bestDirection <= -1`, `casDisRelated <= 1`).

Fixes an off-by-one: Ghidra wrapped both candidate indexes at `1600 <`,
so index 1600 was used once and the code wrote one short past each
1600-entry coordinate array. The original wraps at `>= 1600`
(`cmp 0x640; jl`).

Tribe type 13 has no AITribeType name; it is compared as a literal.

buildRallyPointPathForTribe 69.4 -> 69.7 with the same tile and
best-direction literals.

Left: register and stack-slot allocation in both functions.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
56.6 -> 89.1. Fixes two bugs in the free-slot search copied from Ghidra:
`_ptrState + 0x4e` stepped 78 trees at a time (the original adds 0x9c
bytes, one tree), and the search gave up at `1999 <` instead of the
original's `>= 1999`. It is now an indexed loop like createRock.

Matching changes:
- the state test spelled `type >= 16 && type <= 19` as a switch, so MSVC
  branches like the original instead of emitting sbb
- the apple-colour variation is a signed int compared against the
  literals the original uses (>= 15, >= 13, >= 11, <= 8)
- the stage-4 group is last in the switch, as in the original's layout,
  and types 1 and 4 jump into its shared `= 0` block (the goto is kept
  because the original shares that block)
- the frame index is a plain `RandomLayer & 0x1f`, which MSVC narrows to
  the byte load the original has

Left: register choice for the tile arithmetic and parameter loads.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
57.3 -> 67.6. The eight campground area IDs are an int[8] filled by a loop
(MSVC unrolls and constant-folds it like the original), and the chimp
test is a loop over that array. The area tally is an int[100][2], and
the best-area search is one plain loop instead of Ghidra's five copies.
The grid element is addressed by name rather than through a pointer. The
bounds use the original's literals (`> 399`), the tree test is
`treeID > 0 && treeID < 2000`, and `(char)logic < 0` is `logic & 0x80`.

Left: MSVC strength-reduces `tileY * 400` and the translation-matrix
index into three extra stack slots (frame 0x368 against the original's
0x35c), where the original recomputes them per tile. Moving or inlining
tileY did not change that.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
64.1 -> 100. The field stores are reordered (one and type before x),
which lets the constant 1 from the slot search stay in edx and moves the
edi push past the early return, as in the original. Found by
hill-climbing the order of the independent stores with quick_diff.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
updateNofFpoints (0x0052E120) clears 0x640 bytes from 0x17842FC, i.e.
100 eight-short entries, and the 800 bytes of padding after the declared
[50][8] array are its second half: nofFpointsArrayCopy starts exactly
1600 bytes in.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
The original's clear loop covers the whole 100-entry array; ours stopped
at 50. Left: the original keeps `this` in ecx across
floodFillCasDisFromSignpost (an LTCG build), which needs that callee
reimplemented and listed for /GL.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
89.1 -> 89.6, from hill-climbing the order of the independent field
stores.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
67.4 -> 69.8. Ghidra's first loop advanced a WildlifeGridElement pointer
by 0x640 elements (0x3e800 bytes) per x step and 0x28 elements per y
step, where the original steps one grid column (0x1900 bytes) and one
element (0xa0); everything after the first cell was written far outside
the grid. All three passes are now plain x/y loops over this->grid.

Left: the original keeps `this` in ecx across its three callees (an
LTCG build), which needs them reimplemented and listed for /GL.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Tests the four cardinal neighbours (every second entry of
clockwiseCardinalTranslationMatrix) for an occupied cell with field_0x60
or field_0x64 set. Called by updateSection1034Info.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
A cell qualifies when it has at most 8 unclaimed tiles, at most 4 trees
and at least 50 tiles, and a cardinal neighbour has unknownNonZero01
set. The three guards are separate early returns, which places the
shared return block where the original has it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Breadth-first fill of unknownNonZero01 outwards from one cell, losing
one level per step and skipping cells with more than 10 unclaimed tiles,
through the same 1600-entry ring queue the rally-point search uses. The
candidate coordinates are written back into the cellX/cellY parameters,
which puts them in the parameter's stack slot as in the original.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Clears casDisRelated2 and field_0x74 over the grid, then fills
casDisRelated2 outwards from the attack signpost's cell, up to 100 steps,
through cells of the same separate area that have no unknownNonZero01,
counting each visit in field_0x74.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
…ith /GL

The original keeps `this` in ecx across hasAdjacentCellWithField24Or25,
isAttackStagingCandidateCell, floodFillZoneProximityFromCell and
floodFillCasDisFromSignpost, which LTCG only allows when the callees are
compiled with /GL too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
67.0 -> 79.0 (under /GL). The tile y coordinate is stepped in the outer
loop's header and the loop ends on `y < 405`, the bound the original
tests (as y*12 < 0x12fc); with y derived from gridY MSVC kept a separate
40-count and could not test the y bound through the translation-matrix
offset as the original does. x and y are signed ints compared through
(uint), and the swap flag is a BOOL, which the original keeps in a
dword register.

Left: the binary-map base folded into the y*400 induction variable and
register naming in the five unrolled cell copies.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
The same breadth-first fill as floodFillZoneProximityFromCell, on
field_0x34 and without the unclaimed-tile limit.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
The same breadth-first fill as floodFillField13FromCell, on field_0x50.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
The original keeps `this` in ecx across floodFillField13FromCell and
floodFillField20FromCell, which takes LTCG with both callees compiled
with /GL. updateWildlife goes from 50.3 to 100 with no source change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
The original pushes the tree type it loaded before
getValueFrom0UpTo3ForTreeTypeAndTreeStage again after the call, without
reloading it; LTCG knows the callee leaves edx alone. With both listed,
updateTreeStage goes from 85.7 to 100.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
The original tests isStalked and lays the unstalked counts out last, so the
deer arm's field_0x48 increment cross-jumps into that arm's copy; an
if/else on isStalked != 0 reproduces it. Walking the tile row directly
instead of through a dy offset gives the original's single induction
variable for it (67.6 -> 74.2).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
gynt and others added 4 commits November 29, 2026 11:25
Both neighbour filters end in the same lionCount test in the original,
which MSVC shares between the arms and lays out inline ahead of the
enqueue. Testing deer and lions one at a time, and the lion count on
its own after unstalked units and buildings, reproduces it (71.5 -> 75.8).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
The original calls drawColorBox once per colour arm instead of picking a
colour and drawing once: MSVC hoists the shared coordinate arithmetic
above each chain's last branch and cross-jumps the identical call
tails, which is where its eight extra lea runs come from. 48.9% -> 100%.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
…before its x

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ
@github-actions

Copy link
Copy Markdown

Style guide reading (advisory, posted once)

54 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 17 of the 17 reimplemented .cpp file(s) in this PR.

The match comes first. Where the ugly form is what matched, it stays -- that is the guide's own overriding rule, and rule 21 asks for a one-line comment saying what was measured so the next reader does not retry it. This report is posted once, when the PR opens, and is not repeated on later pushes.

rule what it asks hits
8 Let the compiler unroll 2
9 Prefer for over while/do 9
14 The shape of a file 17
16 Give variables a name that says what they hold 3
18 Use the name, not the number 18
20 Keep nesting low; no goto 2
23 Prefer if-else over ternary 1
24 Declare variables upon first use 2
Where

Rule 8 — Let the compiler unroll

  • src/OpenSHC/Map/WildlifeState/hasAdjacentCellWithField24Or25.cpp:14 — loop steps by 2; try the plain loop and let MSVC unroll
  • src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp:23 — loop steps by 2; try the plain loop and let MSVC unroll

Rule 9 — Prefer for over while/do

  • src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp:45 — while-loop; the guide asks for a for
  • src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp:78 — while-loop; the guide asks for a for
  • src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp:37 — while-loop; the guide asks for a for
  • src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp:98 — while-loop; the guide asks for a for
  • src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp:36 — while-loop; the guide asks for a for
  • src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp:19 — while-loop; the guide asks for a for
  • src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp:19 — while-loop; the guide asks for a for
  • src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp:19 — while-loop; the guide asks for a for
  • src/OpenSHC/Map/WildlifeState/updateNofFpoints.cpp:88 — do-loop; the guide asks for a for

Rule 14 — The shape of a file

  • src/OpenSHC/Map/LandscapeState/createRock.cpp:1 — first include is not LandscapeState; the folder is the class
  • src/OpenSHC/Map/LandscapeState/createTree.cpp:1 — first include is not LandscapeState; the folder is the class
  • src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp:1 — first include is not LandscapeState; the folder is the class
  • src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp:1 — first include is not LandscapeState; the folder is the class
  • src/OpenSHC/Map/WildlifeState/buildRallyPointPathForTribe.cpp:1 — first include is not WildlifeState; the folder is the class
  • src/OpenSHC/Map/WildlifeState/findAndSetNewRallyPointForDeerAndLions.cpp:1 — first include is not WildlifeState; the folder is the class
  • src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp:1 — first include is not WildlifeState; the folder is the class
  • src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp:1 — first include is not WildlifeState; the folder is the class
  • src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp:1 — first include is not WildlifeState; the folder is the class
  • src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp:1 — first include is not WildlifeState; the folder is the class
  • ... and 7 more

Rule 16 — Give variables a name that says what they hold

  • src/OpenSHC/Map/LandscapeState/createTree.cpp:21 — decompiler name uVar1
  • src/OpenSHC/Map/LandscapeState/createTree.cpp:22 — decompiler name uVar3
  • src/OpenSHC/Map/LandscapeState/createTree.cpp:23 — decompiler name uVar4

Rule 18 — Use the name, not the number

  • src/OpenSHC/Map/LandscapeState/createTree.cpp:72 — hex constant 0x7FF; use a name, or decimal
  • src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp:100 — hex constant 0x1000; use a name, or decimal
  • src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp:35 — hex constant 0xFFFFFF; use a name, or decimal
  • src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp:38 — hex constant 0xFFFFFF; use a name, or decimal
  • src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp:41 — hex constant 0xFFFFFF; use a name, or decimal
  • src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp:44 — hex constant 0xFFFFFF; use a name, or decimal
  • src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp:47 — hex constant 0xFFFFFF; use a name, or decimal
  • src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp:50 — hex constant 0xFFFFFF; use a name, or decimal
  • src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp:53 — hex constant 0xFFFFFF; use a name, or decimal
  • src/OpenSHC/Map/WildlifeState/renderDebugDataMapData.cpp:56 — hex constant 0xFFFFFF; use a name, or decimal
  • ... and 8 more

Rule 20 — Keep nesting low; no goto

  • src/OpenSHC/Map/LandscapeState/createTree.cpp:119 — goto; check how many predecessors the target has first
  • src/OpenSHC/Map/LandscapeState/createTree.cpp:145 — goto; check how many predecessors the target has first

Rule 23 — Prefer if-else over ternary

  • src/OpenSHC/Map/LandscapeState/spawnCrowFromNearbyTree.cpp:61 — ternary; the guide prefers extending the if-else chain

Rule 24 — Declare variables upon first use

  • src/OpenSHC/Map/LandscapeState/createRock.cpp:16 — declare _rockID where it is first assigned
  • src/OpenSHC/Map/LandscapeState/createTree.cpp:28 — declare _treeID where it is first assigned

gynt and others added 2 commits December 2, 2026 17:39
Conflicts:
- AttackInfo.hpp: main's version (headers from main lead). Main's Ghidra
  sync already has nof_fpointsArray[100][8] and now types the following
  copy as nof_fpointsArrayCopy[100][8].
- compiler-flags-gl.txt: both sides' entries.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
- WildlifeState::hasAdjacentCellWithField24Or25 returns BOOLEnum on main
  (TRUE/FALSE, same code).
- Tree::unknownDistanceRelatedToCrow is hasCrow on main.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
@github-actions github-actions Bot removed the declaration/type change This requires changes to the generated/exported types or definitions. label Dec 2, 2026
gynt and others added 8 commits December 3, 2026 22:49
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
Full build plus reccmp with both resolver sets enabled, /GL build (the file
stays in compiler-flags-gl.txt). Building updateSection1034Info,
updateNofFpoints, updateWildlife and updateTreeStage as function-visibility
wrapper units instead measured identical to /GL for all four, so the /GL
entries are kept and function-visibility.txt is not changed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
The pass counter is advanced through a volatile read
(pass = *(int volatile*)&pass + 1). With a plain pass++ MSVC sees the
counter unused in the body and reverses the loop into a count-down in
its stack slot; the original counts up (load, add, cmp 20, store).
Build mode: /GL (unchanged), measured with its /GL callees.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
buildRallyPointPathForTribe: 70.6% -> 94.6%. The unit's x is read before y
(the original loads unit.x first, into ebx), and the greedy walk
moves copies walkX/walkY of the start cell (declared y then x) instead of
x/y themselves; the original reloads x/y from their slots and copies
them (mov eax, ebx; mov [esp+0x10], ebp) before the walk. tileY is
computed before tileX. Remaining: stack slot colouring of the BFS locals
and the param_2 copy (mov eax,[esp+0x34] .. mov [esp+0x34],eax) whose
scheduling we do not reproduce. Non-GL build.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
findAndSetNewRallyPointForDeerAndLions: 77.0% -> 88.6%. Same shape as
buildRallyPointPathForTribe: x is read before y, and the walk uses
copies walkX/walkY plus a threshold copy of always2or3or5 (the original
reloads the parameter and stores it back to its home before the walk).
Remaining: stack slot colouring of the walk locals and the threshold
copy scheduled before the RNG read. Non-GL build.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
updateWildlifeGrid: 74.2% -> 87.5%. campgroundAreaIDs is indexed by
player ID 1..8 with slot 0 unused (the original's frame is 0x35c with
the array one dword higher), and the tile rows run over dy 0..9 with
tileY = row + tileY10, where row is read through a volatile so MSVC does
not strength-reduce tileY*400 and translationMatrix[tileY] across the dy
loop (the original recomputes both per tile). Remaining: a clean
ebx/ebp 2-cycle between tile and the shared zero constant (reg_scores
--whyreg: tile takes ebx at a cost-0 tie). Non-GL build.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
buildRallyPointPathForTribe: 94.6% -> 98.0%. One pair of cell
coordinates (cellX/cellY, function scope) serves both the flood fill's
current cell and the walk position, instead of separate candidate and
walk locals. slot_probe.py shows why: sharing one element gives cellY
weight 12 and the first local colour, so it takes the lowest slot and
the cell pointer, areaID and x fall into the original's slots.
Remaining: the original's reload/store of param_2 before the walk and
an esi/edi zero constant, both scheduling. Non-GL build.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
findAndSetNewRallyPointForDeerAndLions: 88.6% -> 96.1%. Same shared
cellX/cellY pair as buildRallyPointPathForTribe, and the threshold copy
of always2or3or5 is taken after the RNG read, as the original reloads
the parameter after the movzx. Remaining: x and the start-cell pointer
swap stack slots (0x14/0x1c), and tileX/tileY register order at the
end of the walk. Non-GL build.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp
gynt and others added 2 commits December 5, 2026 06:00
Writing the check as x < 0 || x > 399 instead of (uint)x > 399 lets the compiler reuse x
for the bound test instead of recomputing it. Also refresh the remarks of createTree and
updateWildlifeGrid with the measured blockers.

SHC_3BB0A8C1_0x0052E120 | 86.6% | Binary-map base folded into the y*400 induction variable; this kept in esi across the flood-fill call

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant